---
title: "Global Average Temperature"
author: "Wanda Bodnar"
output:
flexdashboard::flex_dashboard:
source_code: embed
theme:
version: 4
primary: "black"
navbar-bg: "black"
orientation: columns
vertical_layout: fill
---
```{r setup, include=FALSE}
library(flexdashboard)
```
### Warming stripes { .chart-1 }
```{r}
### Data source: Met Office Hadley Centre (HadCRUT.5.0.1.0)
### Warming stripes: Ed Hawkins
library(ggplot2)
library(RColorBrewer)
library(plotly)
library(tidyr)
library(formattable)
combined <- read.csv(url("https://www.metoffice.gov.uk/hadobs/hadcrut5/data/current/analysis/diagnostics/HadCRUT.5.0.1.0.analysis.summary_series.global.annual.csv"))
names(combined)[1] <- "Year"
names(combined)[2] <- "Anomaly"
combined$Anomaly <- formattable(combined$Anomaly, format = "f", digits = 2)
theme_strip <- theme_minimal()+
theme(axis.text.y = element_blank(),
axis.line.y = element_blank(),
panel.grid.major = element_blank(),
axis.text.x = element_text(vjust = 3, colour = "white", size = 10),
panel.grid.minor = element_blank(),
axis.title = element_blank(),
plot.background = element_rect(fill = "black"),
panel.background = element_rect(fill = "black"),
legend.title = element_text(hjust = 0.5, colour = "white", size = 10),
legend.text = element_text(colour = "white", size = 10))
col_strip <- brewer.pal(11, "RdBu")
c <- ggplot(combined, aes(x = Year, y = 1, fill = Anomaly)) +
geom_tile(aes(text = Anomaly)) +
scale_y_continuous(expand = c(0, 0)) +
scale_x_continuous(breaks = c(1850, 1860, 1870, 1880, 1890, 1900, 1910, 1920,
1930, 1940, 1950, 1960, 1970, 1980, 1990,
2000, 2010, 2020)) +
scale_fill_gradientn(name = "Anomaly / deg C", colors = rev(col_strip)) +
guides(fill = guide_colorbar(barwidth = 0.5)) +
theme_strip
ggplotly(c, tooltip = "text")
```
### Forecast (business as usual) { .chart-2 }
```{r}
### Forecast prediction: https://twitter.com/jrockstrom/status/1482616870394023936
forecast <- read.csv("climate.csv")
annotation <- data.frame(
x = c(2033, 2060),
y = c(1.6, 2.1),
label = c("1.5°C", "2°C"))
f <- ggplot(forecast, aes(x = Year, y = Anomaly)) +
geom_bar(show.legend = FALSE, aes(fill = Anomaly, text = Anomaly), stat = "identity") +
geom_hline(yintercept = 0, linetype = "dotted",
color = "white", size = .5) +
geom_hline(yintercept = 1.5, linetype = "dashed",
color = "white", size = .5) +
geom_hline(yintercept = 2, linetype = "dashed",
color = "white", size = .5) +
scale_fill_gradientn(colors = rev(col_strip)) +
scale_x_continuous(breaks = c(1850, 1860, 1870, 1880, 1890, 1900, 1910, 1920,
1930, 1940, 1950, 1960, 1970, 1980, 1990,
2000, 2010, 2020, 2033, 2060)) +
scale_y_continuous(breaks = c(0, 1.5, 2)) +
geom_text(data = annotation, aes(x = x, y = y, label = label),
color = "white",
size = 5 , angle = 45, fontface = "bold" ) +
ylab("Anomaly / deg C") +
theme(plot.background = element_rect(fill = "black"),
panel.background = element_rect(fill = "black"),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.title.x = element_blank(),
axis.title.y = element_text(colour = "white", size = 10),
axis.text = element_text(colour = "white", size = 10),
axis.line = element_line(colour = "white"),
plot.title = element_text(colour = "white", hjust = 0.5),
plot.subtitle = element_text(colour = "white", hjust = 0.5),
plot.caption = element_text(colour = "white"))
ggplotly(f, tooltip = "text")
```